// Gameplay_SO.cs
using UnityEngine;
using UnityEngine.InputSystem;

[CreateAssetMenu(fileName = "Gameplay_SO", menuName = "Input/GameplayInput")]
public class Gameplay_SO : ScriptableObject, InputControls.IGameplayActions
{
    InputControls inputActions;

    private void OnEnable()
    {
        if (inputActions == null)
        {
            inputActions = new InputControls();
            inputActions.Gameplay.SetCallbacks(this);
        }
        EnableGameplay();
    }

    private void OnDisable()
    {
        DisableAllInputs();
    }

    public void EnableGameplay()
    {
        SwitchActionMap(inputActions.Gameplay);
    }

    void SwitchActionMap(InputActionMap actionMap)
    {
        inputActions.Disable();
        actionMap.Enable();
    }

    public void DisableAllInputs()
    {
        inputActions.Disable();
    }

    public void OnCameraDrag(InputAction.CallbackContext context)
    {
        if (context.performed)
        {
            Vector2 delta = context.ReadValue<Vector2>();
            EventHandler.CallCameraDragEvent(delta);
        }
    }

    public void OnCameraZoom(InputAction.CallbackContext context)
    {
        if (context.performed)
        {
            // 修复：直接读取float值而不是Vector2
            float scrollValue = context.ReadValue<float>();
            EventHandler.CallCameraZoomEvent(scrollValue);
        }
    }
}